package com.dt.dubai.mech.controller;

import com.dt.dubai.mech.entity.MechMarketingActivityEntity;
import com.dt.dubai.mech.controller.innate.MechMarketingActivityInnateAbs;
import com.dt.dubai.core.comm.*;
import com.dt.dubai.core.utile.DateTools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;
import java.util.Map;

/*
* 商户优惠活动记录表
*/

@Controller
@RequestMapping(value = "/mech/mechMarketingActivity")
public class MechMarketingActivityController extends MechMarketingActivityInnateAbs {

    /*innateServiceStart*/
    @Override
    protected void userSavEntity(MechMarketingActivityEntity inEntity, final Long userId) {
        inEntity.setDelSign(false);
    }

    @Override
    protected void userModEntity(MechMarketingActivityEntity inEntity, final Long userId) {
    }

    @Override
    protected void userDelByKey(List<Long> recordIds, final Long userId) {
    }

    @Override
    protected void userQueByKey(Long recordId, Map<String, Object> map, final Long userId) {
        if (null != map && map.size() > 0) {
            map.put("createTxStamp", DateTools.dateFormat((Date) map.get("createTxStamp"), DateTools.DATE_FORMAT_YMD));
            map.remove("adminLoginRecordId");
            map.remove("delSign");
            map.remove("lastupTxStamp");
        }
    }

    @Override
    protected void userQuePageList(PageParameterData queryCondition, List<PageCondition> joinCondition, List<Map<String, Object>> resultMap, final Long userId) {
        for (Map<String, Object> map : resultMap) {
            map.put("createTxStamp", DateTools.dateFormat((Date) map.get("createTxStamp"), DateTools.DATE_FORMAT_YMD));
            Short commodityType = null == map.get("commodityType") ? -1 :  (Short) map.get("commodityType");
            switch (commodityType) {
                case 1:
                    map.put("commodityType", commodityType);
                    map.put("commodityTypeStr", "电商");
                    break;
                case 2:
                    map.put("commodityType", commodityType);
                    map.put("commodityTypeStr", "检测");
                    break;
                case 3:
                    map.put("commodityType", commodityType);
                    map.put("commodityTypeStr", "计量");
                    break;
                default:
                    map.put("commodityType", -1);
                    map.put("commodityTypeStr", "未知");
            }
            if (null != map.get("startTime"))
                map.put("startTime", DateTools.dateFormat((Date) map.get("startTime"), DateTools.DATE_FORMAT_YMD));
            if (null != map.get("endTime"))
                map.put("endTime", DateTools.dateFormat((Date) map.get("endTime"), DateTools.DATE_FORMAT_YMD));
            Short yesRelease = null == map.get("yesRelease") ? -1 :  (Short) map.get("yesRelease");
            switch (yesRelease) {
                case 1:
                    map.put("yesRelease", yesRelease);
                    map.put("yesReleaseStr", "未发布");
                    break;
                case 2:
                    map.put("yesRelease", yesRelease);
                    map.put("yesReleaseStr", "已发布");
                    break;
                default:
                    map.put("yesRelease", -1);
                    map.put("yesReleaseStr", "未知");
            }
            map.remove("delSign");
            map.remove("lastupTxStamp");
        }
    }

    /*innateServiceEnd*/
    /*以上内容请误删除或是移动，系统升级使用，用户代码请写入下方*/
}